var pageNum=1,pageSize=4,pageTotal=0;
var pageNum2=1,pageSize2=4,pageTotal2=0;
var pageNum3=1,pageSize3=4,pageTotal3=0;
$(function(){
	loadAllZhaoPingMessage();
	$("#queryAllZhaoPingMessageTable").show();
});
function loadAllZhaoPingMessage(){
	utilAjax("/recruitment_msg/queryAllRecruitment_msg","pageNum="+pageNum2+"&pageSize="+pageSize2,"get",
			function(data){
		pageNum2 = data.pageNum;
		pageSize2 = data.pageSize;
		pageTotal2 = data.pages;
		parseAllZhaoPingMessage(data.list);
	});
}
function showAllZhaoPingMessage(){
	$("#recMessageTable").hide();
	$("#queryAllZhaoPingMessageTable").show();
	$("#GGFaBuZhaoPingMessageTable").hide();
	loadAllZhaoPingMessage();
}
function parseAllZhaoPingMessage(lists){
	var zpCon = "";
	if(lists!=""){
		zpCon+="<tr><td colspan='14' align='center'><font size='5'>所有招聘信息</font></td></tr>" +
			"<tr class='info text-info'><td>编号</td><td>标题</td><td>联系电话</td><td>薪资范围</td>"+
			"<td>招聘岗位</td><td align='center'>招聘者姓名</td><td align='center'>要求工作年限</td>"+
			"<td>学历要求</td><td>福利待遇</td><td>状态</td>"+
			"<td>审核状态</td><td>公司名</td><td>公司地址</td><td>创建时间</td>"+
		"</tr>";
		$.each(lists,function(i,r){
			var rec_workYear = "";//设置经验年限
			if(r.rec_workYear==1){rec_workYear = "在校生"}
			if(r.rec_workYear==2){rec_workYear = "应届生"}
			if(r.rec_workYear==3){rec_workYear = "一年以内"}
			if(r.rec_workYear==4){rec_workYear = "1-5年"}
			if(r.rec_workYear==5){rec_workYear = "5-10年"}
			if(r.rec_workYear==6){rec_workYear = "10年以上"}
			var rec_qualification = "";//设置学历要求
			if(r.rec_qualification==1){rec_qualification = "初中及以下"}
			if(r.rec_qualification==2){rec_qualification = "中专/技校"}
			if(r.rec_qualification==3){rec_qualification = "高中"}
			if(r.rec_qualification==4){rec_qualification = "大专"}
			if(r.rec_qualification==5){rec_qualification = "本科"}
			if(r.rec_qualification==6){rec_qualification = "硕士"}
			if(r.rec_qualification==7){rec_qualification = "博士"}
			var rec_msg_check_state = "";
			if(r.rec_msg_check_state==1){rec_msg_check_state = "通过"}
			if(r.rec_msg_check_state==2){rec_msg_check_state = "未通过"}
			if(r.rec_msg_check_state==3){rec_msg_check_state = "审核中"}
			zpCon += "<tr>" +
					"<td width='35'>"+r.rec_id+"</td>" +
					"<td width='100'><textarea rows='2' class='form-control' style='font-size:10px;' readonly='disabled'>"+r.rec_title+"</textarea></td>" +
					"<td>"+r.rec_phone+"</td>" +
					"<td width='75'>"+r.rec_pay_min+"--"+r.rec_pay_max+"</td>" +
					"<td width='140'><textarea rows='2' class='form-control' style='font-size:10px;' readonly='disabled'>"+r.rec_duty+"</textarea></td>" +
					"<td width='50' align='center'>"+r.rec_name+"</td>" +
					"<td width='60' align='center'>"+rec_workYear+"</td>" +
					"<td width='60'>"+rec_qualification+"</td>" +
					"<td width='140'><textarea class='form-control' rows='2' style='font-size:10px;' readonly='disabled'>"+r.rec_welfare+"</textarea></td>" +
					"<td width='30'>"+(r.rec_msg_state==1?"<font color='green'>上架</font>":"<font color='red'>下架</font>")+"</td>" +
					"<td width='45'>"+rec_msg_check_state+"</td>" +
					"<td width='90'>"+r.rec_company_name+"</td>" +
					"<td>"+r.rec_company_address+"</td>" +
					"<td>"+dateUtil(r.create_time)+"</td>" +
				"</tr>";
		});
		zpCon+= "<tr><td colspan='14' align='center'>当前页:"+pageNum2+"/总页数:"+pageTotal2+"</td></tr>";
		zpCon+= "<tr><td colspan='14' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页' onclick=changeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页' onclick=changeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页' onclick=changeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='末页' onclick=changeZhaoPingMessagePage(this)> " +
			"</td></tr>";
	}else{
		zpCon+= "<tr><td align='center'><font size='6' color='red'>暂无举报信息</font></td></tr>";
	}
	$("#queryAllZhaoPingMessageTable").html(zpCon);
}

function changeZhaoPingMessagePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum2=1;
		loadAllZhaoPingMessage();
		break;
	case "上一页":
		if(pageNum2>1){
			pageNum2--;
			loadAllZhaoPingMessage();
		}	
		break;
	case "下一页":
		if(pageNum2<pageTotal2){
			pageNum2++;
			loadAllZhaoPingMessage();
		}
		break;
	case "末页":
		pageNum2=pageTotal2;
		loadAllZhaoPingMessage();
		break;
	}
}

function showJuBaoMessage(){
	$("#recMessageTable").show();
	$("#queryAllZhaoPingMessageTable").hide();
	$("#GGFaBuZhaoPingMessageTable").hide();
	loadRecMessage();
}
function loadRecMessage(){
	utilAjax("/report_recruitment_msg/queryAllRri_report_state","pageNum="+pageNum+"&pageSize="+pageSize,"get",
			function(data){
		pageNum = data.pageNum;
		pageSize = data.pageSize;
		pageTotal = data.pages;
		parseRecMessage(data.list);
	});
}

function parseRecMessage(lists){
	var juBaoCon = "<tr><td colspan='9' align='center'><font size='5'>所有举报招聘信息</font></td></tr>" +
			"<tr class='info text-info'><td>消息编号</td><td>举报内容</td><td>求职者姓名</td><td>招聘者姓名</td><td>审核状态</td><td>操作</td></tr>";
	if(lists!=""){
		$.each(lists,function(i,j){
			juBaoCon += "<tr>"+
						"<td>"+j.rri_id+"</td>"+
						"<td><textarea class='form-control' rows='2' style='font-size:10px;' readonly='disabled'>"+j.rri_context+"</textarea></td>"+
						"<td>"+j.basic_information.basic_name+"</td>"+
						"<td>"+j.recruitment_msg.recruiter_basic.recruiter_name+"</td>"+
						"<td>"+(j.rri_report_state==3?"<font color='green'>未审核</font>":'')+"</td>"+
						"<td>" +
							"<input type='button' class='btn btn-default' value='通过审核' onclick=judgmentOfAudit("+j.rri_id+",2)> " +
							"<input type='button' class='btn btn-default' value='拒绝审核' onclick=judgmentOfAudit("+j.rri_id+",1)>"+
						"</td>"+
					"</tr>";
		});
		juBaoCon+= "<tr><td colspan='7' align='center'>当前页:"+pageNum+"/总页数:"+pageTotal+"</td></tr>";
		juBaoCon+= "<tr><td colspan='7' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页' onclick=changeJuBaoMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='末页' onclick=changeJuBaoMessagePage(this)> " +
			"</td></tr>";
	}else{
		juBaoCon+= "<tr><td colspan='7' align='center'><font size='6' color='red'>暂无举报信息</font></td></tr>";
	}
	
	$("#recMessageTable").html(juBaoCon);
}
function judgmentOfAudit(rri_id,rri_report_state){
	utilAjax("/report_recruitment_msg/updateRri_report_state",
			"rri_id="+rri_id+"&rri_report_state="+rri_report_state,"post",
			function(flag){
		if(flag){
			alert("审核成功");
			loadRecMessage();
		}else{
		}
	});
}
function changeJuBaoMessagePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum=1;
		loadRecMessage();
		break;
	case "上一页":
		if(pageNum>1){
			pageNum--;
			loadRecMessage();
		}	
		break;
	case "下一页":
		if(pageNum<pageTotal){
			pageNum++;
			loadRecMessage();
		}
		break;
	case "末页":
		pageNum=pageTotal;
		loadRecMessage();
		break;
	}
}

function showGGFaBuZhaoPingMessage(){
	$("#recMessageTable").hide();
	$("#queryAllZhaoPingMessageTable").hide();
	$("#GGFaBuZhaoPingMessageTable").show();
	loadGGFaBuZhaoPingMessage();
}
function loadGGFaBuZhaoPingMessage(){
	utilAjax("/recruitment_msg/queryGGFaBuZhaoPingMessage","pageNum="+pageNum3+"&pageSize="+pageSize3,"get",
			function(data){
		pageNum3 = data.pageNum;
		pageSize3 = data.pageSize;
		pageTotal3 = data.pages;
		parseGGFaBuZhaoPingMessage(data.list);
	});
}
function parseGGFaBuZhaoPingMessage(lists){
	var zpCon = "";
	if(lists!=""){
		zpCon+="<tr class='info text-info'>"+
			"<caption>所有未审核招聘信息</caption>"+
			"<td>编号</td><td>标题</td><td>联系电话</td><td>薪资范围</td>"+
			"<td>招聘岗位</td><td>招聘者姓名</td><td>要求工作年限</td>"+
			"<td>学历要求</td><td>福利待遇</td>"+
			"<td>审核状态</td><td>公司名</td><td>公司地址</td><td>创建时间</td><td>操作</td>"+
		"</tr>";
		$.each(lists,function(i,r){
			var rec_workYear = "";//设置经验年限
			if(r.rec_workYear==1){rec_workYear = "在校生"}
			if(r.rec_workYear==2){rec_workYear = "应届生"}
			if(r.rec_workYear==3){rec_workYear = "一年以内"}
			if(r.rec_workYear==4){rec_workYear = "1-5年"}
			if(r.rec_workYear==5){rec_workYear = "5-10年"}
			if(r.rec_workYear==6){rec_workYear = "10年以上"}
			var rec_qualification = "";//设置学历要求
			if(r.rec_qualification==1){rec_qualification = "初中及以下"}
			if(r.rec_qualification==2){rec_qualification = "中专/技校"}
			if(r.rec_qualification==3){rec_qualification = "高中"}
			if(r.rec_qualification==4){rec_qualification = "大专"}
			if(r.rec_qualification==5){rec_qualification = "本科"}
			if(r.rec_qualification==6){rec_qualification = "硕士"}
			if(r.rec_qualification==7){rec_qualification = "博士"}
			var rec_msg_check_state = "";
			if(r.rec_msg_check_state==1){rec_msg_check_state = "通过"}
			if(r.rec_msg_check_state==2){rec_msg_check_state = "未通过"}
			if(r.rec_msg_check_state==3){rec_msg_check_state = "审核中"}
			zpCon += "<tr>" +
			"<td width='35'>"+r.rec_id+"</td>" +
			"<td width='100'><textarea rows='2' class='form-control' style='font-size:10px;' readonly='disabled'>"+r.rec_title+"</textarea></td>" +
			"<td>"+r.rec_phone+"</td>" +
			"<td width='75'>"+r.rec_pay_min+"--"+r.rec_pay_max+"</td>" +
			"<td width='140'><textarea rows='2' class='form-control' style='font-size:10px;' readonly='disabled'>"+r.rec_duty+"</textarea></td>" +
			"<td width='50' align='center'>"+r.rec_name+"</td>" +
			"<td width='60' align='center'>"+rec_workYear+"</td>" +
			"<td width='60'>"+rec_qualification+"</td>" +
			"<td width='140'><textarea class='form-control' rows='2' style='font-size:10px;' readonly='disabled'>"+r.rec_welfare+"</textarea></td>" +
			"<td width='45'>"+rec_msg_check_state+"</td>" +
			"<td width='90'>"+r.rec_company_name+"</td>" +
			"<td>"+r.rec_company_address+"</td>" +
			"<td>"+dateUtil(r.create_time)+"</td>" +
			"<td width='75'>" +
			"<input type='button' class='btn btn-default' value='通过审核' onclick=tongGuoShenHe("+r.rec_id+",1)> "+
			"<input type='button' class='btn btn-default' value='拒绝审核' onclick=tongGuoShenHe("+r.rec_id+",2)>"+
			"</td>"+
		"</tr>";
		});
		zpCon+= "<tr><td colspan='15' align='center'>当前页:"+pageNum3+"/总页数:"+pageTotal3+"</td></tr>";
		zpCon+= "<tr><td colspan='15' align='center'>" +
				"<input type='button' class='btn btn-default' value='首页' onclick=changeShenHeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='上一页' onclick=changeShenHeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='下一页' onclick=changeShenHeZhaoPingMessagePage(this)> " +
				"<input type='button' class='btn btn-default' value='末页' onclick=changeShenHeZhaoPingMessagePage(this)> " +
			"</td></tr>";
	}else{
		zpCon+= "<tr><td align='center'><font size='6' color='red'>暂无审核未通过的信息</font></td></tr>";
	}
	$("#GGFaBuZhaoPingMessageTable").html(zpCon);
}

function tongGuoShenHe(rec_id,rec_msg_check_state){
		utilAjax("/recruitment_msg/updateFaBuZhaoPingMessagRec_msg_check_state","rec_id="+rec_id+"&rec_msg_check_state="+rec_msg_check_state,"post",
				function(flag){
			if(flag){
				alert("审批成功");
				loadGGFaBuZhaoPingMessage();
			}else{
			}
		});
}
function changeShenHeZhaoPingMessagePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum3=1;
		loadGGFaBuZhaoPingMessage();
		break;
	case "上一页":
		if(pageNum3>1){
			pageNum3--;
			loadGGFaBuZhaoPingMessage();
		}	
		break;
	case "下一页":
		if(pageNum3<pageTotal3){
			pageNum3++;
			loadGGFaBuZhaoPingMessage();
		}
		break;
	case "末页":
		pageNum3=pageTotal3;
		loadGGFaBuZhaoPingMessage();
		break;
	}
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}


function dateUtil(times){
	var date = new Date(times);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	Y = date.getFullYear() + '-';
	M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date
			.getMonth() + 1)
			+ '-';
	D = date.getDate() + ' ';
	var dateCon = Y + M + D;
	return dateCon;
}